package com.project2.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.project2.bean.CommonData;
import com.project2.bean.bo.AdminCommentBo;
import com.project2.bean.po.MarketComment;
import com.project2.bean.po.MarketCommentExample;
import com.project2.mapper.MarketCommentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class AdminCommentServiceImpl implements AdminCommentService {

    @Autowired
    MarketCommentMapper commentMapper;

    @Override
    public CommonData<MarketComment> getGoodsComment(AdminCommentBo commentBo) {
        MarketCommentExample marketCommentExample = new MarketCommentExample();
        MarketCommentExample.Criteria criteria = marketCommentExample.createCriteria();

        criteria.andDeletedEqualTo(false);

        if (commentBo.getUserId()!=null){
            criteria.andUserIdEqualTo(commentBo.getUserId());
        }
        if (commentBo.getValueId()!=null){
            criteria.andValueIdEqualTo(commentBo.getValueId());
        }
        marketCommentExample.setOrderByClause(commentBo.getSort()+" "+commentBo.getOrder());

        PageHelper.startPage(commentBo.getPage(),commentBo.getLimit());

        List<MarketComment> marketComments = commentMapper.selectByExample(marketCommentExample);

        PageInfo pageInfo = new PageInfo(marketComments);

        return CommonData.data(pageInfo);
    }

    @Override
    public int deleteComment(MarketComment comment) {
        Date date = new Date();
        Integer commentId = comment.getId();
        int i = commentMapper.updateByCommentId(commentId,date);
        return i;
    }


}
